﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Configuration;

namespace JohnnySins.Admin
{
    public partial class Admin : System.Web.UI.MasterPage
    {
        private string[] chatPages = { "/livebroadcast.aspx", "/videochat.aspx" };

        protected void Page_Load(object sender, EventArgs e)
        {
            if (ConfigurationManager.AppSettings["IsDevelopmentEnvironment"] == null)
            {
                string urlCurrent = Request.Url.ToString().ToLower();
                if (!urlCurrent.Contains("//www."))
                {
                    string newUrl = urlCurrent.Replace("http://", "http://www.").Replace("https://", "https://www.");
                    Response.Redirect(newUrl, false);
                }
            }
        }

        protected void lbLogout_Click(object sender, EventArgs e)
        {
            FormsAuthentication.SignOut();
            Session.Abandon();

            // clear authentication cookie
            HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
            cookie1.Expires = DateTime.Now.AddYears(-1);
            Response.Cookies.Add(cookie1);

            // clear session cookie (recommend)
            HttpCookie cookie2 = new HttpCookie("ASP.NET_SessionId", "");
            cookie2.Expires = DateTime.Now.AddYears(-1);
            Response.Cookies.Add(cookie2);

            FormsAuthentication.RedirectToLoginPage();
        }
    }
}